﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Web.Mvc;

using ProjectBase.Core;
using ProjectBase.Core.Dao;
using ProjectBase.Core.Service;

namespace ProjectBase.Mvc.Web
{
    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]
    public abstract class ExceptionBaseAttribute : ActionFilterAttribute, IExceptionFilter
    {
        #region IExceptionFilter Members
        public abstract void OnException(ExceptionContext filterContext);
        #endregion

        /// <summary>
        ///     Dispose the Application based objects (singeltons etc.)
        ///     Dispose the Factory (e.g. NHibernate) on applicaton break down.
        ///     Such cleaning will allow to re-initiate without application restart 
        ///     (e.g. when SQL server connection is restored)
        /// </summary>
        protected virtual void DisposeApplicationObjects()
        {
            NHSession.Dispose();
            DbSession.Dispose();
        }

        #region session providers
        INHSessionHandler _nhSession;
        protected virtual INHSessionHandler NHSession
        {
            get { return _nhSession ?? (_nhSession = Factory.CreateInstance<INHSessionHandler>()); }
        }
        IDbSessionHandler _dbSession;
        protected virtual IDbSessionHandler DbSession
        {
            get { return _dbSession ?? (_dbSession = Factory.CreateInstance<IDbSessionHandler>()); }
        }
        IXmlSessionHandler _xmlSession;
        protected virtual IXmlSessionHandler XmlSession
        {
            get { return _xmlSession ?? (_xmlSession = Factory.CreateInstance<IXmlSessionHandler>()); }
        }
        #endregion session providers
    }
}